package com.diy.sigmund.diycommon.test.controller.excel.easyexcel;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import java.math.BigDecimal;

/**
 * 导出顺序，默认以属性从上到下的顺序为准
 * 写入列的顺序可以进行指定，在实体类注解上指定index，从小到大，从左到右排列
 *
 * @author ylm-sigmund
 * @since 2021/9/14 17:48
 */
public class RespCustomerDailyExport implements Converter<String> {

    // @ExcelProperty(value = {"主标题", "客户编码"}, converter = RespCustomerDailyExport.class)
    @ExcelProperty(value = "客户编码", converter = RespCustomerDailyExport.class)
    private String customerName;
    // @ExcelProperty({"主标题", "MIS编码"})
    // @ExcelIgnore
    @ExcelProperty("MIS编码")
    private String misCode;
    // @ExcelProperty({"主标题", "月度滚动额"})
    @ExcelProperty("月度滚动额")
    private BigDecimal monthlyQuota;

    @ExcelProperty("最新应收账款余额")
    private BigDecimal accountReceivableQuota;

    @NumberFormat("#.##%")
    @ExcelProperty("本月利率(年化）")
    private BigDecimal dailyInterestRate;

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getMisCode() {
        return misCode;
    }

    public void setMisCode(String misCode) {
        this.misCode = misCode;
    }

    public BigDecimal getMonthlyQuota() {
        return monthlyQuota;
    }

    public void setMonthlyQuota(BigDecimal monthlyQuota) {
        this.monthlyQuota = monthlyQuota;
    }

    public BigDecimal getAccountReceivableQuota() {
        return accountReceivableQuota;
    }

    public void setAccountReceivableQuota(BigDecimal accountReceivableQuota) {
        this.accountReceivableQuota = accountReceivableQuota;
    }

    public BigDecimal getDailyInterestRate() {
        return dailyInterestRate;
    }

    public void setDailyInterestRate(BigDecimal dailyInterestRate) {
        this.dailyInterestRate = dailyInterestRate;
    }

    @Override
    public Class supportJavaTypeKey() {
        return String.class;
    }

    /**
     * 判断单元格类型
     */
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    /**
     * 将excel对象转成Java对象，这里读的时候会调用
     */
    @Override
    public String convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
            GlobalConfiguration globalConfiguration) throws Exception {
        return cellData.getStringValue();
    }

    /**
     * 将Java对象转成String对象，写出的时候调用
     *
     * @return
     */
    @Override
    public WriteCellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
            GlobalConfiguration globalConfiguration) {
        // GlobalConfiguration的属性autoTrim只针对value，不包括这里返回的值
        return new WriteCellData<String>("         自定义：" + value);
    }
}
